<template>
  <div class="search-table-page">
    <Row type="flex"
         justify="space-between"
         class="row-operation">
      <i-col span="24">
        <!-- <search-form :userType="userType"
                   @search="handleSearch"></search-form> -->
      </i-col>
      <!-- <Col span="8"
           class="col-right">
      <add class="spteen"
           @getList="getTableData"></add>
      <Poptip confirm
              title="确定删除？"
              @on-ok="okdelete">
        <Button icon="md-trash"
                type="error">删除</Button>
      </Poptip>
      </Col> -->
    </Row>
    <table-page :loading="loading"
                :columns1="columns1"
                :data1="tableData"
                :noData="noData"
                :currentPage="currentPage"
                :totalPage="totalPage"
                :pageSize="pageSize"
                @multi-select="multiSelect"
                @change-page="changePage"
                @change-page-size="changPageSize">
    </table-page>
    <edit ref="edit"></edit>
  </div>
</template>

<script>
import edit from './edit/edit'
import searchForm from './search-form/search-form'
import tablePage from '_c/table-page/table-page'
import { getSellerAuditList, editSellerAudit } from '@/api/seller'

export default {
  name: 'seller-audit',
  components: {
    edit,
    searchForm,
    tablePage
  },
  data () {
    return {
      exportLoading: false,
      loading: false,
      columns1: [
        {
          title: '手机号',
          key: 'PhoneNum'
        },
        {
          title: '店铺名称',
          key: 'BusinessName'
        },
        {
          title: '营业执照号码',
          key: 'BusinessLicenseNum'
        },
        {
          title: '法人姓名',
          key: 'LegalPersonName'
        },
        {
          title: '法人身份证号码',
          key: 'LegalPersonIDCareNo'
        },
        {
          title: '申请时间',
          key: 'CreateTime'
        },
        {
          title: '注册来源',
          key: 'RegistSource'
        },
        {
          title: '审核状态',
          key: 'IsAgree',
          render: (h, params) => {
            const text = params.row.IsAgree === 0 ? '不通过' : '通过'
            return h('span', text)
          }
        },
        {
          title: '推荐人',
          key: 'RefereeName'
        },
        {
          title: '经营种类',
          key: 'TypeName'
        },
        {
          title: '操作',
          key: 'handle',
          width: 140,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                on: {
                  click: () => {
                    this.$refs.edit.getItem(params.row.BusinessApplyID)
                  }
                }
              }, '查看'),
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  'margin-left': '5px'
                },
                on: {
                  click: () => {
                    this.changSellerAudit(params.row.BusinessApplyID, params.row.IsAgree)
                  }
                }
              }, '审核')
            ])
          }
        }
      ],
      noData: '暂无数据',
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      tableData: [],
      selectedIds: [],
      searchData: {
        'PageIndex': '1',
        'PageSize': '10',
        'Search': []
      }
    }
  },
  mounted () {
    this.init()
    this.getTableData()
  },
  methods: {
    init () {
      this.searchData = {
        'PageIndex': '1',
        'PageSize': '10',
        'Search': []
      }
    },
    // 获取表格数据信息
    getTableData (parameter) {
      this.loading = true
      parameter = this.searchData
      getSellerAuditList(parameter).then(res => {
        if (res.data.success) {
          // console.log(res.data.data.aaData)
          this.totalPage = res.data.data.TotalCount
          this.currentPage = res.data.data.CurrentPageIndex
          this.tableData = res.data.data.aaData
          this.loading = false
        } else {
          this.$Message.info(res.data.msg || '缺少必要参数！')
          this.loading = true
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 页码切换
    changePage (page) {
      this.currentPage = page
      this.searchData.PageIndex = page
      this.getTableData()
    },
    // 切换每页显示多少条数据
    changPageSize (pageSize) {
      this.init()
      this.pageSize = pageSize
      this.searchData.PageSize = pageSize
      this.getTableData()
    },
    handleSearch (searchContent) {
      this.searchData.Search = searchContent
      // console.log(this.searchData)
      this.getTableData(this.searchData)
    },
    // 多选
    multiSelect (selection) {
      this.selectedIds = selection.map(item => item.Id)
    },
    okdelete () {
      if (this.selectedIds.length === 0) {
        this.$Message.info('请选择要删除的用户！')
      } else {
        const delData = {
          SysUserId: localStorage.getItem('userId'),
          Ids: this.selectedIds
        }
        delSystemUser(delData).then(res => {
          if (res.data.success) {
            this.$Message.info(res.data.msg)
          } else {
            this.$Message.info(res.data.msg)
          }
        }).then(() => {
          this.getTableData()
        })
      }
    },
    changSellerAudit (id, isAgree) {
      const IsAgree = isAgree === 0 ? 1 : 0
      const requestData = {
        SysUserId: localStorage.getItem('userId'),
        BusinessApplyID: id,
        IsAgree
      }
      editSellerAudit(requestData).then(res => {
        if (res.data.success) this.$Message.success('操作成功！')
        else this.$Message.info(res.data.msg || '操作失败！')
      }).then(() => {
        this.getTableData()
      })
    }
  }
}
</script>

<style lang="less" scoped>
.search-table-page {
  padding: 20px;
  min-height: 85vh;
  background-color: #fff;
  .row-operation {
    margin-bottom: 20px;
    .col-right {
      text-align: right;
      .spteen {
        margin-left: 5px;
      }
    }
  }
}
</style>
